import { BaseState } from "./BaseState";

/**
 * 状态机可转换的配置
 */
export class Translations {
    translationMap:Map<BaseState, Set<BaseState>> = new Map();
    
    Pass(from:BaseState, to:BaseState):boolean {
        let pass = false;
        if (this.translationMap.has(from)) {
            let toSet:Set<BaseState> = this.translationMap.get(from);
            if (toSet.has(to)) {
                pass = true;
            }
        }
        return pass;
    }

    AddTranslation(from:BaseState, to:BaseState) {
        let toStateSet:Set<BaseState>;
        if (this.translationMap.has(from)) {
            toStateSet = this.translationMap.get(from);
        }
        else {
            toStateSet = new Set<BaseState>();
        }
        toStateSet.add(to);
        this.translationMap.set(from, toStateSet);
    }
}
